package mblog.core.persist.service.impl;

import com.alibaba.fastjson.JSONObject;
import mblog.base.utils.WeiBoUtils;
import mblog.core.persist.service.WeiBoService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * Project  : mblog
 * Author   : Wu Tian Qiang
 * Date     : 2016/8/1
 */
@Service
public class WeiBoServiceImpl implements WeiBoService {

    @Value("#{configProperties['follow.message']}")
    private String followMessage = "欢迎关注闲适悦-电影分享";

    @Override
    public String handleEvent(JSONObject message) {
        String eventType = message.getJSONObject("data").getString("subtype");
        String returnMessage = "";
        switch (eventType) {
            case "unfollow":
                returnMessage = handleUnFollowEvent(message);
                break;
            case "follow":
                returnMessage = handleFollowEvent(message);
                break;
        }
        return returnMessage;
    }

    /**
     * 处理取消关注事件
     *
     * @param message
     */
    private String handleUnFollowEvent(JSONObject message) {
        return "";
    }

    /**
     * 处理关注事件
     *
     * @param message
     */
    private String handleFollowEvent(JSONObject message) {
        Long receiverId = message.getLong("sender_id");
        Long senderId = message.getLong("receiver_id");
        return WeiBoUtils.replyTextMsg(this.followMessage, senderId, receiverId);
//        WeiBoUtils.sendTextMsg(this.followMessage, receiverId);
//        return "";
    }


}
